<?php 
	function displayAlbumNames() {
		$albumNames = mysql_query("select name, albumId from albums");
		$html = "<select name='album' id='alb'>";
		while($row = mysql_fetch_row($albumNames)) {
			$value = $row[0];
			$id = $row[1];
			//echo  "<br />" . $id . "-" . $value;
			$html .= "<option value='$id'>$value</option>";
		}
		$html .= "</select>";
	
		return $html;
	}
	
	require_once 'db-connection.php';
?>
	<form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post" />
		<label for="alb">Choose Album to Display:</label>
		<?php echo displayAlbumNames();?>
		<input type="submit" name="submit" value="Display!" />
	</form>
<?php 
	if(isset($_POST['submit'])) {
		$albumId = $_POST["album"];
		$imgs = mysql_query("select imgId from album_img_rel where albumId = $albumId;");
		echo "<ul>";
		while($row = mysql_fetch_row($imgs)) {
			$imageId = $row[0];
			//echo $imageId;
			$getImgName = mysql_query("select name from images where imgId = $imageId;");
			$imgRow = mysql_fetch_row($getImgName);
			$imageName = $imgRow[0];
			echo "<li><img src='images/$imageName' /></li>";
		}
		echo "</ul>";
	}
?>